// add html to beginning of playlist
function playlistAddEntry(html, q) {
	$("#playlist-list").append(html);
	$("#entry_"+q).hide().slideDown().tooltip({ 
		delay: 0, 
		showURL: false, 
		track: true,
		fade: 250,
		bodyHandler: function() { 
			return $("<img/>").attr("src", $(this).attr("thumbnail"));
		} 
	});
	playlistExamine();
}

// remove from list
function playlistRemoveEntry(video) {
	$('#entry_' + video).slideUp(function() {
		$('#entry_' + video).remove();
		playlistExamine();
	});
}

// cue next song
function playlistCueNext(slot, remove) {
	if (playlistGetLength() > 0) {
		video = playlistGetVidId("#playlist-list > div:first");
		printLog('Cueing next video from playlist: '+video+' in slot ' + slot);
		videoCue(video, slot, 0);
		if (remove) {
			playlistRemoveEntry(video);
		}
		return true;
	} else {
		return false;
	}
}

// play next song
function playlistPlayNext(slot, remove) {
	if (playlistGetLength() > 0) {
		video = playlistGetVidId("#playlist-list > div:first");
		printLog('Playing next video from playlist: '+video+' in slot ' + slot);
		videoLoad(video, slot, 0);
		if (remove) {
			playlistRemoveEntry(video);
		}
		return true;
	} else {
		return false;
	}
}

// check playlist
function playlistExamine() {
	// not working!!
	if (autoDJ && playlistGetLength() < minPlaylistLength + 1) {
		printLog("AutoDJ: playlist too small, add some songs")
		loadEntryFromLFM();
	}
	// sortable!
	$("#playlist-list").sortable({ 
		revert: true
	});
}

// items in playlist
function playlistGetLength() {
	return $("#playlist-list > div").length;
}

// get video id
function playlistGetVidId(jqueryselector) {
	return $(jqueryselector).attr("id").replace('entry_','');
}

// already in playlist?
function playlistVidExists(video) {
	// doesn't matter, always add video, so always return false;
	return false;
	//return $("#playlist-list div#entry_"+video).length > 0;
}